import { DataItemProvider, ListDataProvider } from '../../interface';

/**
 * 快捷操作栏控制器
 *
 * @author chitanda
 * @date 2022-06-28 13:06:32
 * @export
 * @class QuickActionController
 */
export class QuickActionController {
  protected dom: HTMLQuickActionBarElement;

  /**
   * 快捷操作栏是否已经隐藏
   *
   * @author chitanda
   * @date 2022-07-07 14:07:19
   * @readonly
   * @type {boolean}
   */
  get isHidden(): boolean {
    return this.dom.isHidden;
  }

  /**
   * 是否悬浮在操作栏上
   *
   * @author chitanda
   * @date 2022-07-07 15:07:15
   * @readonly
   * @type {boolean}
   */
  get isHover(): boolean {
    return this.dom.isHover;
  }

  /**
   * Creates an instance of QuickActionController.
   *
   * @author chitanda
   * @date 2022-06-28 17:06:21
   */
  constructor() {
    this.dom = document.createElement('quick-action-bar');
    document.body.appendChild(this.dom as unknown as HTMLElement);
  }

  /**
   * 打开快捷操作栏，并设置列表数据
   *
   * @author chitanda
   * @date 2022-06-28 17:06:27
   * @param {DataItemProvider[]} list
   * @return {*}  {Promise<void>}
   */
  open(provider: ListDataProvider<DataItemProvider>): Promise<void> {
    return this.dom.open(provider);
  }

  /**
   * 隐藏操作栏
   *
   * @author chitanda
   * @date 2022-06-29 15:06:08
   * @return {*}  {Promise<void>}
   */
  hide(): Promise<void> {
    return this.dom.hide();
  }

  /**
   * 触发快捷操作栏的键盘事件
   *
   * @author chitanda
   * @date 2022-07-07 16:07:49
   * @param {string} keys
   * @param {string} [action]
   * @return {*}  {Mousetrap.MousetrapInstance}
   */
  trigger(keys: string, action?: string): Mousetrap.MousetrapInstance {
    return Mousetrap.trigger(keys, action);
  }
}
